package com.dimao.certificate_build_service.Util.asyncReadFile;

import com.dimao.certificate_build_service.handle.Executor;
import com.dimao.certificate_build_service.handle.Handler;
import com.dimao.certificate_build_service.handle.ValueResult;
import io.vertx.core.Vertx;

public class KeyReader extends Reader<String> {
    public KeyReader(Vertx vertx) {
        super(vertx);
    }

    @Override
    public Executor<Handler<ValueResult<String>>> read(String file) {
        return h->getVertx().fileSystem().readFile(file, result->{
            if(result.failed())
                h.handle(new ValueResult<>(false, null, result.cause()));
            else h.handle(new ValueResult<>(true,
                    result.result().toString(), null));
        });
    }
}
